package com.cens.mall.ssoclient.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

@Controller
public class HelloController {

    @Value("${sso.server.url}")
    String ssoServerUrl;

    /**
     * 无需登录即可访问
     * @return
     */
    @GetMapping("/hello")
    public String hello(){
        return "hello";
    }

    @GetMapping("/emps")
    public String emps(Model model, HttpSession session){
        Object loginUser = session.getAttribute("loginUser");
        if(loginUser == null){
            return "redirect:" + ssoServerUrl+"?redirect_url=http://client1.com:8082/emps";
        }else{
            List<String> emp = new ArrayList<>();
            emp.add("cens");
            emp.add("maby");
            model.addAttribute("emps",emp);
            return "list";
        }
    }
}
